
/*INCLUDES *******************************************************************/
#include "ses_scheduler.h"
#include "ses_buzzer.h"


/* FUNCTION DEFINITIONS ******************************************************/
void buzzer_stop(){
	//remove the buzzing function from the scheduler
	//scheduler_remove(buzzer_start);

	//set TC0 to normal mode
	TCCR0A &= ~(1 << COM0B1) & ~(1 << WGM01)& ~(1 << WGM00);
	TCCR0B &= ~(1 << WGM02);

	//set pin direction to input, stoping the output
	BUZZER_DDR &= ~(1 << BUZZER_PIN);

}

void buzzer_start() {
	//set pin change interval in OCR0B so that the pwm does not start yet
	OCR0B = 0x7F;
	OCR0A = 0xFF;

	//set TC0 to fast PWM with OCR0A as TOP and toggle pin on match with OCR0B
	TCCR0A = (1 << COM0B1) | (1 << WGM01)| (1 << WGM00);

	//set TC0 prescaler to clk/64 and set WGM02 for fast PWM with OCR0A as TOP
	TCCR0B = (1 << CS01)| (1 << CS00)| (1 << WGM02);

	//set pin direction
	BUZZER_DDR |= (1 << BUZZER_PIN);
}




